﻿/*******************************************************************************
 * Copyright @ 2017 YunSpace.Framework 版权所有
 * Author: GaoTang
 * Description: YunSpace 快速开发平台
 * Website：http://www.yunspace.com.cn
*********************************************************************************/
#region USING SYSTEM
using YunSpace.Application.SiteLibraryManage;
using YunSpace.Domain.Entity.SiteLibraryManage;
using YunSpace.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YunSpace.Domain.ViewModel.SiteLibraryManage;
using YunSpace.Web.Common;
#endregion

namespace YunSpace.Web.Areas.SiteManage.Controllers
{
    public class PriceScheduleController : ControllerBase
    {
        private PriceScheduleApp pricescheduleApp = new PriceScheduleApp();

        
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = pricescheduleApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetPriceScheduleJson(string F_SpaceId)
        {
            var data = pricescheduleApp.GetPriceScheduleList(F_SpaceId);
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = pricescheduleApp.GetForm(keyValue);
            return Content(data.ToJson());
        }

        /// <summary>
        /// 提交表单
        /// </summary>
        /// <param name="pricescheduleEntity">表单实体</param>
        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult SubmitForm([ModelBinder(typeof(JsonBinder<PriceScheduleOutPut>))]PriceScheduleOutPut priceScheduleOutPut)
        {
            pricescheduleApp.DeleteDateForm(priceScheduleOutPut.sDate, priceScheduleOutPut.eDate);
            pricescheduleApp.SubmitList(priceScheduleOutPut.PriceScheduleList);

            return Success("操作成功。");
        }

        /// <summary>
        /// 删除表单
        /// </summary>
        /// <param name="keyValue">表单主键</param>
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            pricescheduleApp.DeleteForm(keyValue);

            return Success("删除成功。");
        }
    }
}


